<template>
  <div class="wrapper">
    <HeaderPart>
      添加商品
    </HeaderPart>
    <div class="form">
      <el-form style="margin-top: 5rem" :model="foodInfo" label-width="80px">
        <el-form-item label="商品名称:">
          <el-input v-model="foodInfo.name" />
        </el-form-item>
        <el-form-item label="商家价格:">
          <el-input v-model="foodInfo.price" />
        </el-form-item>
        <el-form-item label="商品描述:">
          <el-input v-model="foodInfo.description" />
        </el-form-item>
        <el-form-item label="商品封面">
          <el-input v-model="foodInfo.imgUrl" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import {useRoute, useRouter} from "vue-router";
import {ref} from "vue";
import HeaderPart from "@/components/common/HeaderPart";
import {addFood} from "@/utils/api/FoodManager";

// 接收shopId
const shopId = parseInt(useRoute().params.shopId)
// 定义shop对象
const foodInfo = ref({shopId})
// 创建门店的方法
const router = useRouter()
const onSubmit =async ()=>{
  console.log(foodInfo)
  const res = await addFood(foodInfo.value)
  if(res.flag){
    foodInfo.value = null
    router.go(-1)
  }
}
</script>

<style scoped>
.wrapper {
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
}
.wrapper .form {
  width: 300px;
}
</style>